"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Handler = void 0;
const Big_1 = require("../Big");
const Utils_1 = __importDefault(require("../Utils"));
/**
 * 对局对战类
 */
class Handler {
    constructor(gameMgr) {
        this.gameMgr = gameMgr;
    }
    gc() {
        this.gameMgr = null;
    }
    /** 行动失败 */
    fail(user, message) {
        user.sendObj(Utils_1.default.getObj("fail", { "message": message }));
    }
    //小子出大 {"data":{"end":"(-4.5,9)","start":"(-5.5,9)"},"isGame":true,"method":"smallBornBig"}
    smallBornBig(data, user) {
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let small = startPoint.small;
        let oldBig = endPoint.big;
        if (oldBig != null) {
            this.fail(user, "出大失败");
            oldBig.expose();
            return;
        }
        let big = new Big_1.Big(this.gameMgr, small.player, endPoint, small, null);
        this.gameMgr.sendBroadcast(Utils_1.default.getObj("born_big", { "big": big.toObj() }));
    }
    //大子出大
    bigBornBig(data, user) {
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        let big_end = endPoint.big;
        if (big_end != null) {
            this.fail(user, "出大失败");
            big_end.expose();
            return;
        }
        let big = new Big_1.Big(this.gameMgr, big_start.player, endPoint, big_start.mother, big_start);
        this.gameMgr.sendBroadcast(Utils_1.default.getObj("born_big", { "big": big.toObj() }));
    }
    //大子移动
    bigMove(data, user) {
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        let big_end = endPoint.big;
        if (big_end != null) {
            this.fail(user, "移动失败");
            big_end.expose();
            return;
        }
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(Utils_1.default.getObj("move_big", { "start": data.start, "end": data.end }));
    }
}
exports.Handler = Handler;
